import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hello_flutter/bloc_demo/weather/settings_bloc/index.dart';

import '../weather.dart';
import 'temperature_widget.dart';
import 'weather_condition_widget.dart';

/// CombinedWeatherTemperature
///
class CombinedWeatherTemperature extends StatelessWidget {
  final Weather weather;

  CombinedWeatherTemperature({
    Key key,
    @required this.weather,
  })  : assert(weather != null),
        super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            Padding(
              padding: EdgeInsets.all(20.0),
              child: WeatherConditions(condition: weather.condition),
            ),
            Padding(
                padding: EdgeInsets.all(20.0),
                //  inject the TemperatureUnits into the Temperature widget.
                child: BlocBuilder<SettingsBloc, SettingsState>(
                    builder: (context, state) {
                  return Temperature(
                      temperature: weather.temp,
                      high: weather.maxTemp,
                      low: weather.minTemp,
                      units: state.temperatureUnits);
                })),
          ],
        ),
        Center(
          child: Text(
            weather.formattedCondition,
            style: TextStyle(fontSize: 30, fontWeight: FontWeight.w200),
          ),
        ),
      ],
    );
  }
}
